package com.example.wlf.gamerecorder;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.NumberPicker;

import java.lang.reflect.Field;

public class CustomNumberPicker extends NumberPicker {
    public CustomNumberPicker(Context context) {
        super(context);
    }

    public CustomNumberPicker(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomNumberPicker(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void addView(View child) {
        super.addView(child);
        updateView(child);
    }

    @Override
    public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) {
        super.addView(child, index, params);
        updateView(child);
    }

    @Override
    public void addView(View child, android.view.ViewGroup.LayoutParams params) {
        super.addView(child, params);
        updateView(child);
    }

    public void updateView(View view) {
        if (view instanceof EditText) {
            // 文字颜色、大小
            ((EditText) view).setTextColor(ContextCompat.getColor(getContext(), R.color.error_color_material_light));
            ((EditText) view).setTextSize(40f);
        }
    }



    /**
     * 初始化滚动框布局
     */
    public void initNumberPicker(int MaxValue,int MinValue,int value) {
        //workingAge_view = LayoutInflater.from(this).inflate(R.layout.popupwindow, null);
        //submit_workingAge = (Button) workingAge_view.findViewById(R.id.submit_workingAge);
        //numberPicker = (NumberPicker) findViewById(R.id.score_1);
        setMaxValue(MaxValue);
        setMinValue(MinValue);
        setValue(value);
        setFocusable(false);
        //numberPicker.setFocusableInTouchMode(false);
        setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
        //设置NumberPicker，中间的EditView不可以点击
        //setNumberPickerDividerColor(numberPicker);
    }



}
